package
{
	//imports
	import flash.display.MovieClip;
	import flash.text.*;
	import flash.utils.*;
	import flash.events.*;
	
	public class FPS extends MovieClip
	{
		private var lastFrameTime:Number;
		private var framesPerSecond:Number;
		var fpsCounter:TextField;

		public function FPS():void
		{
			fpsCounter = TextField(getChildByName("frReadout"));
			
			this.addEventListener(Event.ENTER_FRAME, frameUpdate);
			
			var myTimer:Timer = new Timer(1000);
			myTimer.addEventListener(TimerEvent.TIMER, timerUpdate);
			myTimer.start();
		}
		
		private function frameUpdate(evt:Event):void
		{
			var now:Number = getTimer();
			var elapsed:Number = now - lastFrameTime;
			framesPerSecond = Math.round(1000/elapsed);
			
			lastFrameTime = now;
		}
		
		private function timerUpdate (evt:Event):void
		{
			fpsCounter.text = String(framesPerSecond);
		}
	}
}